package qlsl.androiddesign.popupwindow.subwindow;

import java.util.List;

import com.qlsl.androiddesign.kuaiwa.R;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.GridView;
import android.widget.LinearLayout.LayoutParams;
import qlsl.androiddesign.activity.baseactivity.BaseActivity;
import qlsl.androiddesign.adapter.subadapter.CarBrandAdapter;
import qlsl.androiddesign.entity.otherentity.CarBrand;
import qlsl.androiddesign.popupwindow.basewindow.PopupWindow;

/**
 * 品牌PopupWindow<br/>
 */
@SuppressLint("ViewConstructor")
public class BrandPopupWindow extends PopupWindow {

	private GridView gridView;

	public BrandPopupWindow(BaseActivity activity) {
		super(activity);
		initView();
		setPopupWindowAttribute();
		initData();
	}

	@SuppressLint("InflateParams")
	private void initView() {
		LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rootView = inflater.inflate(R.layout.window_brand, null);
		setContentView(rootView);
		gridView = (GridView) rootView.findViewById(R.id.gridView);
	}

	private void setPopupWindowAttribute() {
		setWidth(LayoutParams.MATCH_PARENT);
		setHeight(LayoutParams.WRAP_CONTENT);
		setFocusable(true);
		setAnimationStyle(R.style.AnimTop);
		ColorDrawable colorDrawable = new ColorDrawable(
				activity.getResources().getColor(R.color.bg_common_content_view));
		setBackgroundDrawable(colorDrawable);
		setOutsideTouchable(true);
	}

	private void initData() {

	}

	public void setGridViewData(List<CarBrand> list) {
		CarBrandAdapter adapter = new CarBrandAdapter(activity, list, gridView);
		gridView.setAdapter(adapter);
	}

	public CarBrand getSelectItem() {
		CarBrandAdapter adapter = (CarBrandAdapter) gridView.getAdapter();
		if (adapter.getCount() > 0) {
			return adapter == null ? null : adapter.getItem(adapter.getSelectPosition());
		} else {
			return null;
		}
	}

}
